/* Copyright Andy Mitchell 2007. No warranties */

function GIXMLHttpRequest(gtdinboxPage){
	this._gtdinboxPage = gtdinboxPage;
	this._httpRequests = [];
};

GIXMLHttpRequest.prototype.process = function(request){
	// request: {url:"", callback:function}
try{
	
	if( request ) this._httpRequests.push(request);
	if( this._httpRequestInProgress ){	// in action
		return;
	}
	if( this._httpRequests.length==0 ) return;
	
	var request = this._httpRequests[0];
	var url = request.url;
	var callback = request.callback;
	this._httpRequestInProgress = url;
	this._httpRequests.splice(0,1);
		
	var req = new XMLHttpRequest();
	req.open('GET', url, true);
	req.onreadystatechange = GIPROTOTYPE.bind(this, function(aEvt){
		try{
		if (req.readyState==4) {
			if( req.status==200 ){
				if( callback ) callback(req);
			}
			this._httpRequestInProgress = null;
			this.process();
		}
		}catch(e){
			if( GTDDEBUGMODE ) alert("gixmlhttprequest process statechange\n" + e.toString());
		}
	});
	req.send(null);
}catch(e){
	if( GTDDEBUGMODE ) alert("GIXMLHttpRequest processHttpRequest\n" + e.toString());
}
};